﻿using DevExpress.XtraEditors;
using Lamex.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mIE.Calculate
{
    public class LGC_VAL_BOM_P74
    {

        //"B、如果包含P74
        //a、子程序1、通过[BOM].[DRAWING_NO]条件，传参【P74_包铝材_L1000】、【P74_包铝材_L1001】、【1000】，返回
        //b、子程序2、通过[BOM].[COMPONENT]条件，传参【P74_包遮光胶条】，返回

        //c、遍历抽出BOM数据中的[BOM].[COMPONENT]
        //返回逻辑
        //IF [BOM].[COMPONENT]物料出现在[B_IE_COMPONENT_NECESSARY].[Material_No]
        //  【P74_包其他配件】=1
        //   跳出判断
        //END IF

        //【P74_清洗】=1"
        public static DataTable LGC_VAL_BOM_P74_VALUE(DataTable dt_BOM, string DWG_No, string Part_No, string Process_Code, string WORKTIME_LOGIC_CODE)
        {
            string errorMsg = DWG_No + Part_No + Process_Code;
            try
            {
                //a.子程序1
                DataTable dt1 = Calculate.LGC_VAL_BOM_SUB1.LGC_VAL_BOM_SUB1_VALUE("P74_包铝材_L1000", "P74_包铝材_L1001", 1000, dt_BOM, DWG_No, Part_No, Process_Code, WORKTIME_LOGIC_CODE);
                //b.子程序2
                DataTable dt2 = Calculate.LGC_VAL_BOM_SUB2.LGC_VAL_BOM_SUB2_VALUE(dt_BOM, DWG_No, Part_No, Process_Code, WORKTIME_LOGIC_CODE,
                    "P74_包遮光胶条");
                //c
                DataTable dt3 = Common.GetTable.GetTable_Feature();
                double Feature_CheckA_VALUE = 0;
                if (dt_BOM.Rows.Count > 0)
                {
                    for (int i = 0; i < dt_BOM.Rows.Count; i++)
                    {
                        DataTable dtTemp = BaseBuildSql.GetDataTableBySql("select FEATURE_NAME from IE_BOM_Comp_MatCheck where CHECK_MAT='" + dt_BOM.Rows[i]["COMPONENT"].ToString() + "' and FEATURE_NAME='P74_包面盖配件' ");
                        if (dtTemp.Rows.Count > 0)
                            Feature_CheckA_VALUE = 1;
                    }
                    if (Feature_CheckA_VALUE > 0)
                    {
                        DataRow dr = dt3.NewRow();
                        dr["DWG_NO"] = DWG_No;
                        dr["PART_NO"] = Part_No;
                        dr["PROCESS_CODE"] = Process_Code;
                        dr["FEATURE_NAME"] = "P74_包面盖配件";
                        dr["FEAT_VALUE"] = Feature_CheckA_VALUE;
                        dr["LABOR_VALUE"] = Calculate.LGC_TIM_VTA.LGC_TIM_VTA_VALUE(DWG_No, Part_No, "P74_包面盖配件", "", Feature_CheckA_VALUE);//根据特征定义表工时字段计算
                        dr["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                        dr["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                        dt3.Rows.Add(dr);
                    }
                }
                //d
                DataTable dt4 = Common.GetTable.GetTable_Feature();
                DataRow dr4 = dt4.NewRow();
                dr4["DWG_NO"] = DWG_No;
                dr4["PART_NO"] = Part_No;
                dr4["PROCESS_CODE"] = Process_Code;
                dr4["FEATURE_NAME"] = "P74_清洗";
                dr4["FEAT_VALUE"] = 1;
                dr4["LABOR_VALUE"] = Calculate.LGC_TIM_VTA.LGC_TIM_VTA_VALUE(DWG_No, Part_No, "P74_清洗", "", 1);//根据特征定义表工时字段计算
                dr4["UPDATE_TIME"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                dr4["UPDATE_USER"] = Lamex.Common.Loginer.CurrentUser.AccountName;
                dt4.Rows.Add(dr4);

                //合并3个Datatable
                DataTable dtResult = new DataTable();
                dtResult.Merge(dt1);
                dtResult.Merge(dt2);
                dtResult.Merge(dt3);
                dtResult.Merge(dt4);

                return dtResult;
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(errorMsg + ex.Message);
                return null;
            }
        }
        

}
}
